package org.mdrtwell.designpattern.creational.singleton;

/**
 * 
 * @author x
 * 
 */
class DoubleCheckLockingSingleton {
	private static DoubleCheckLockingSingleton	instance	= null;
	private static Object						lockObj		= new Object();

	public static DoubleCheckLockingSingleton getInstance() {
		if (instance == null) {
			synchronized (lockObj) {
				if (instance == null) {
					instance = new DoubleCheckLockingSingleton();
				}
			}
		}
		return instance;
	}

	private DoubleCheckLockingSingleton() {
	}
}

class LazyNonThreadSafeSingleton {
	private static LazyNonThreadSafeSingleton	instance	= null;

	public static LazyNonThreadSafeSingleton getInstance() {
		if (instance == null) {
			instance = new LazyNonThreadSafeSingleton();
		}
		return instance;
	}

	private LazyNonThreadSafeSingleton() {
	}
}

class LazyThreadSafeSingleton {
	private static LazyThreadSafeSingleton	instance	= null;
	private static Object					lockObj		= new Object();

	public static LazyThreadSafeSingleton Instance() {
		synchronized (lockObj) {
			if (instance == null) {
				instance = new LazyThreadSafeSingleton();
			}
			return instance;
		}
	}

	private LazyThreadSafeSingleton() {
	}
}

class NonLazyThreadSafeSingleton {
	private static NonLazyThreadSafeSingleton	instance	= new NonLazyThreadSafeSingleton();

	public static NonLazyThreadSafeSingleton Instance() {
		return instance;
	}

	private NonLazyThreadSafeSingleton() {
	}
}
